 

package com.zdkj.admin.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.admin.api.entity.SysUserInfoChange;
import com.zdkj.admin.service.SysUserInfoChangeService;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.zdkj.admin.api.feign.RemoteSupportService;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;


/**
 * 人员变更信息查询
 *
 * @author zdkj code generator
 * @date 2020-06-03 21:45:35
 */
@RestController
@AllArgsConstructor
@RequestMapping("/sysuserinfochange" )
@Api(value = "sysuserinfochange", tags = "人员变更信息查询")
public class SysUserInfoChangeController {

    private final SysUserInfoChangeService sysUserInfoChangeService;
	private final RemoteSupportService remoteSupportService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysUserInfoChange 人员变更信息查询
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSysUserInfoChangePage(Page page, SysUserInfoChange sysUserInfoChange) {
        boolean userNameFlag=false;
        boolean userCodeFlag=false;
        String userNameLike=null;
        String userCodeLike=null;
        if (sysUserInfoChange.getUserName()!=null){
            userNameLike=sysUserInfoChange.getUserName();
            userNameFlag=true;
            sysUserInfoChange.setUserName(null);
        }
        if (sysUserInfoChange.getUserCode()!=null){
            userCodeLike=sysUserInfoChange.getUserCode();
            userCodeFlag=true;
            sysUserInfoChange.setUserCode(null);
        }
		if(sysUserInfoChange.getLineNew()!=null){
		   String newLineName = remoteSupportService.getLineNameByCode(sysUserInfoChange.getLineNew()).getData();
			sysUserInfoChange.setLineNew(newLineName);
		}
		List<String> dateCondition = sysUserInfoChange.getDates1();

        QueryWrapper queryWrapper = Wrappers.query(sysUserInfoChange);
        if (ObjectUtil.isNotEmpty(dateCondition)) {
            queryWrapper.between("create_time", dateCondition.get(0), dateCondition.get(1));
        }
		
        queryWrapper.like(userNameFlag,"user_name",userNameLike);
        queryWrapper.like(userCodeFlag,"user_code",userCodeLike);
		queryWrapper.orderByDesc("CREATE_TIME");
        return R.ok(sysUserInfoChangeService.page(page, queryWrapper));
    }


    /**
     * 通过id查询人员变更信息
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(sysUserInfoChangeService.getById(id));
    }



    /**
     * 通过id删除用户信息变更记录
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除用户信息变更记录", notes = "通过id删除用户信息变更记录")
    @SysLog("通过id删除用户信息变更记录" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('sys_userchangeinfo_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(sysUserInfoChangeService.removeById(id));
    }

    /**
     * 批量删除
     * @param ids ids
     * @return R
     */
    @ApiOperation(value = "批量删除用户信息变更记录", notes = "批量删除用户信息变更记录")
    @SysLog("批量删除用户信息变更记录" )
    @DeleteMapping("/delBatch" )
    @PreAuthorize("@pms.hasPermission('sys_userchangeinfo_delBatch')" )
    public R removeByIds(@RequestBody List<Integer> ids) {
        return R.ok(sysUserInfoChangeService.removeByIds(ids));
    }

}
